"""
商品相关的Schema模型
"""
from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field


class PriceHistoryItem(BaseModel):
    """单条价格历史记录"""
    id: int
    product_id: int
    product_sn: str
    price: float
    original_price: Optional[float] = None
    recorded_at: datetime
    change_reason: Optional[str] = None
    
    class Config:
        from_attributes = True


class PriceStatistics(BaseModel):
    """价格统计信息"""
    current_price: float = Field(description="当前价格")
    highest_price: float = Field(description="最高价")
    lowest_price: float = Field(description="最低价")
    average_price: float = Field(description="平均价")
    price_trend: str = Field(description="价格趋势: up/down/stable")
    change_rate: float = Field(description="价格变化率（%）")
    is_lowest_recently: bool = Field(description="是否近期最低价")


class PriceHistoryResponse(BaseModel):
    """价格历史响应"""
    success: bool = True
    product_id: int
    product_sn: str
    product_name: str
    days: int = Field(description="查询天数")
    statistics: PriceStatistics
    history: List[PriceHistoryItem]
    total: int = Field(description="历史记录总数")


class PriceChartData(BaseModel):
    """价格图表数据（简化版）"""
    date: str
    price: float
    original_price: Optional[float] = None
    reason: Optional[str] = None

